﻿//////////////////////////////////////////////////////////////
// <auto-generated>This code was generated by LLBLGen Pro 5.9.</auto-generated>
//////////////////////////////////////////////////////////////
// Code is generated on: 
// Code is generated using templates: SD.TemplateBindings.SharedTemplates
// Templates vendor: Solutions Design.
//////////////////////////////////////////////////////////////
using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Xml.Serialization;
using LLBLGenPro.OrmCookbook.HelperClasses;
using LLBLGenPro.OrmCookbook.FactoryClasses;
using LLBLGenPro.OrmCookbook.RelationClasses;

using SD.LLBLGen.Pro.ORMSupportClasses;

namespace LLBLGenPro.OrmCookbook.EntityClasses
{
	// __LLBLGENPRO_USER_CODE_REGION_START AdditionalNamespaces
	// __LLBLGENPRO_USER_CODE_REGION_END
	/// <summary>Entity class which represents the entity 'ProductLine'.<br/><br/></summary>
	[Serializable]
	public partial class ProductLineEntity : CommonEntityBase, Recipes.IProductLine<ProductEntity>
		// __LLBLGENPRO_USER_CODE_REGION_START AdditionalInterfaces
		// __LLBLGENPRO_USER_CODE_REGION_END	
	{
		private EntityCollection<ProductEntity> _products;

		// __LLBLGENPRO_USER_CODE_REGION_START PrivateMembers
		// __LLBLGENPRO_USER_CODE_REGION_END
		private static ProductLineEntityStaticMetaData _staticMetaData = new ProductLineEntityStaticMetaData();
		private static ProductLineRelations _relationsFactory = new ProductLineRelations();

		/// <summary>All names of fields mapped onto a relation. Usable for in-memory filtering</summary>
		public static partial class MemberNames
		{
			/// <summary>Member name Products</summary>
			public static readonly string Products = "Products";
		}

		/// <summary>Static meta-data storage for navigator related information</summary>
		protected class ProductLineEntityStaticMetaData : EntityStaticMetaDataBase
		{
			public ProductLineEntityStaticMetaData()
			{
				SetEntityCoreInfo("ProductLineEntity", InheritanceHierarchyType.None, false, (int)LLBLGenPro.OrmCookbook.EntityType.ProductLineEntity, typeof(ProductLineEntity), typeof(ProductLineEntityFactory), false);
				AddNavigatorMetaData<ProductLineEntity, EntityCollection<ProductEntity>>("Products", a => a._products, (a, b) => a._products = b, a => a.Products, () => new ProductLineRelations().ProductEntityUsingProductLineKey, typeof(ProductEntity), (int)LLBLGenPro.OrmCookbook.EntityType.ProductEntity);
			}
		}

		/// <summary>Static ctor</summary>
		static ProductLineEntity()
		{
		}

		/// <summary> CTor</summary>
		public ProductLineEntity()
		{
			InitClassEmpty(null, null);
		}

		/// <summary> CTor</summary>
		/// <param name="fields">Fields object to set as the fields for this entity.</param>
		public ProductLineEntity(IEntityFields2 fields)
		{
			InitClassEmpty(null, fields);
		}

		/// <summary> CTor</summary>
		/// <param name="validator">The custom validator object for this ProductLineEntity</param>
		public ProductLineEntity(IValidator validator)
		{
			InitClassEmpty(validator, null);
		}

		/// <summary> CTor</summary>
		/// <param name="productLineKey">PK value for ProductLine which data should be fetched into this ProductLine object</param>
		public ProductLineEntity(System.Int32 productLineKey) : this(productLineKey, null)
		{
		}

		/// <summary> CTor</summary>
		/// <param name="productLineKey">PK value for ProductLine which data should be fetched into this ProductLine object</param>
		/// <param name="validator">The custom validator object for this ProductLineEntity</param>
		public ProductLineEntity(System.Int32 productLineKey, IValidator validator)
		{
			InitClassEmpty(validator, null);
			this.ProductLineKey = productLineKey;
		}

		/// <summary>Private CTor for deserialization</summary>
		/// <param name="info"></param>
		/// <param name="context"></param>
		protected ProductLineEntity(SerializationInfo info, StreamingContext context) : base(info, context)
		{
			// __LLBLGENPRO_USER_CODE_REGION_START DeserializationConstructor
			// __LLBLGENPRO_USER_CODE_REGION_END
		}

		/// <summary>Method which will construct a filter (predicate expression) for the unique constraint defined on the fields: ProductLineName .</summary>
		/// <returns>true if succeeded and the contents is read, false otherwise</returns>
		public IPredicateExpression ConstructFilterForUCProductLineName()
		{
			var filter = new PredicateExpression();
			filter.Add(LLBLGenPro.OrmCookbook.HelperClasses.ProductLineFields.ProductLineName == this.Fields.GetCurrentValue((int)ProductLineFieldIndex.ProductLineName));
 			return filter;
		}

		/// <summary>Creates a new IRelationPredicateBucket object which contains the predicate expression and relation collection to fetch the related entities of type 'Product' to this entity.</summary>
		/// <returns></returns>
		public virtual IRelationPredicateBucket GetRelationInfoProducts() { return CreateRelationInfoForNavigator("Products"); }
		
		/// <inheritdoc/>
		protected override EntityStaticMetaDataBase GetEntityStaticMetaData() {	return _staticMetaData; }

		/// <summary>Initializes the class members</summary>
		private void InitClassMembers()
		{
			PerformDependencyInjection();
			// __LLBLGENPRO_USER_CODE_REGION_START InitClassMembers
			// __LLBLGENPRO_USER_CODE_REGION_END
			OnInitClassMembersComplete();
		}

		/// <summary>Initializes the class with empty data, as if it is a new Entity.</summary>
		/// <param name="validator">The validator object for this ProductLineEntity</param>
		/// <param name="fields">Fields of this entity</param>
		private void InitClassEmpty(IValidator validator, IEntityFields2 fields)
		{
			OnInitializing();
			this.Fields = fields ?? CreateFields();
			this.Validator = validator;
			InitClassMembers();
			// __LLBLGENPRO_USER_CODE_REGION_START InitClassEmpty
			// __LLBLGENPRO_USER_CODE_REGION_END

			OnInitialized();
		}

		/// <summary>The relations object holding all relations of this entity with other entity classes.</summary>
		public static ProductLineRelations Relations { get { return _relationsFactory; } }

		/// <summary>Creates a new PrefetchPathElement2 object which contains all the information to prefetch the related entities of type 'Product' for this entity.</summary>
		/// <returns>Ready to use IPrefetchPathElement2 implementation.</returns>
		public static IPrefetchPathElement2 PrefetchPathProducts { get { return _staticMetaData.GetPrefetchPathElement("Products", CommonEntityBase.CreateEntityCollection<ProductEntity>()); } }

		/// <summary>The ProductLineKey property of the Entity ProductLine<br/><br/></summary>
		/// <remarks>Mapped on  table field: "ProductLine"."ProductLineKey".<br/>Table field type characteristics (type, precision, scale, length): Int, 10, 0, 0.<br/>Table field behavior characteristics (is nullable, is PK, is identity): false, true, true</remarks>
		public virtual System.Int32 ProductLineKey
		{
			get { return (System.Int32)GetValue((int)ProductLineFieldIndex.ProductLineKey, true); }
			set { SetValue((int)ProductLineFieldIndex.ProductLineKey, value); }		}

		/// <summary>The ProductLineName property of the Entity ProductLine<br/><br/></summary>
		/// <remarks>Mapped on  table field: "ProductLine"."ProductLineName".<br/>Table field type characteristics (type, precision, scale, length): NVarChar, 0, 0, 50.<br/>Table field behavior characteristics (is nullable, is PK, is identity): false, false, false</remarks>
		public virtual System.String ProductLineName
		{
			get { return (System.String)GetValue((int)ProductLineFieldIndex.ProductLineName, true); }
			set	{ SetValue((int)ProductLineFieldIndex.ProductLineName, value); }
		}

		/// <summary>Gets the EntityCollection with the related entities of type 'ProductEntity' which are related to this entity via a relation of type '1:n'. If the EntityCollection hasn't been fetched yet, the collection returned will be empty.<br/><br/></summary>
		[TypeContainedAttribute(typeof(ProductEntity))]
		public virtual EntityCollection<ProductEntity> Products { get { return GetOrCreateEntityCollection<ProductEntity, ProductEntityFactory>("ProductLine", true, false, ref _products); } }

		// __LLBLGENPRO_USER_CODE_REGION_START CustomEntityCode
		// __LLBLGENPRO_USER_CODE_REGION_END

	}
}

namespace LLBLGenPro.OrmCookbook
{
	public enum ProductLineFieldIndex
	{
		///<summary>ProductLineKey. </summary>
		ProductLineKey,
		///<summary>ProductLineName. </summary>
		ProductLineName,
		/// <summary></summary>
		AmountOfFields
	}
}

namespace LLBLGenPro.OrmCookbook.RelationClasses
{
	/// <summary>Implements the relations factory for the entity: ProductLine. </summary>
	public partial class ProductLineRelations: RelationFactory
	{
		/// <summary>Returns a new IEntityRelation object, between ProductLineEntity and ProductEntity over the 1:n relation they have, using the relation between the fields: ProductLine.ProductLineKey - Product.ProductLineKey</summary>
		public virtual IEntityRelation ProductEntityUsingProductLineKey
		{
			get { return ModelInfoProviderSingleton.GetInstance().CreateRelation(RelationType.OneToMany, "Products", true, new[] { ProductLineFields.ProductLineKey, ProductFields.ProductLineKey }); }
		}

	}
	
	/// <summary>Static class which is used for providing relationship instances which are re-used internally for syncing</summary>
	internal static class StaticProductLineRelations
	{
		internal static readonly IEntityRelation ProductEntityUsingProductLineKeyStatic = new ProductLineRelations().ProductEntityUsingProductLineKey;

		/// <summary>CTor</summary>
		static StaticProductLineRelations() { }
	}
}
